#include <iostream>
using namespace std;
#include <wx/wx.h>
#include <wx/cmdline.h>
#include <wx/datetime.h>
#include <wx/log.h>
const wxCmdLineEntryDesc cmdLineDesc[] = {
	{wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP},
	{wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose")},
	{wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet")},
	{wxCMD_LINE_OPTION, _T("o"), _T("output"), _T("output file")},
	{wxCMD_LINE_OPTION, _T("i"), _T("input"), _T("input dir")},
	{wxCMD_LINE_OPTION, _T("s"), _T("size"), _T("output block size"), wxCMD_LINE_VAL_NUMBER},
	{wxCMD_LINE_OPTION, _T("d"), _T("date"), _T("output file date"), wxCMD_LINE_VAL_DATE},
	{wxCMD_LINE_PARAM, NULL, NULL, _T("input file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE},
	{wxCMD_LINE_NONE}
};
void ShowCmdLine(const wxCmdLineParser &parser)
{
	wxString s = _T("Command line parsed successfully:\nInput files: ");
	size_t count = parser.GetParamCount();
	for(size_t param = 0; param < count; param++) {
		s << parser.GetParam(param) << _T(' ');
	}
	s << _T('\n') 
	  << _T("Verbose:\t") << (parser.Found(_T("v"))? _T("yes"): _T("no")) << _T('\n') 
	  << _T("Quiet:\t") << (parser.Found(_T("q"))? _T("yes"): _T("no")) << _T('\n');
	wxString strVal;
	long lVal;
	wxDateTime dt;
	if (parser.Found(_T("o"), &strVal))
		s << _T("Output file:\t") << strVal << _T('\n');
	if (parser.Found(_T("i"), &strVal))
		s << _T("Input dir:\t") << strVal << _T('\n');
	if (parser.Found(_T("d"), &dt))
		s << _T("Date:\t") << dt.FormatISODate() << _T('\n');
	if (parser.Found(_T("project_name"), &strVal))
		s << _T("Project:\t") << strVal << _T('\n');
	wxLogMessage(s);
}
int main(int argc, char **argv)
{
#if wxUSE_UNICODE
	wxChar **wxArgv = new wxChar *[argc + 1];
	{
		int n;
		for(n = 0; n < argc; n++) {
			wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
			wxArgv[n] = wxStrdup(warg);
		}
		wxArgv[n] = NULL;
	}
#else
	#define wxArgv argv
#endif
	wxChar *buf[] = {
		0, _T("a"), _T("b"), _T("c"), _T("-o main.cpp"), _T("-v"), _T("-q")
	};
	wxChar **p = buf;
	wxCmdLineParser parser(cmdLineDesc, 7, p); 
//	wxCmdLineParser parser(cmdLineDesc, argc, wxArgv); 
	switch(parser.Parse()) {
		case -1:
			wxLogMessage(_T("Help was given, terminating"));
			break;
		case 0:
			ShowCmdLine(parser);
			break;
		default:
			wxLogMessage(_T("Syntax error detected, aborting."));
			break;
	}
	return 0;
}

